////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2012 Kentaro Sekimoto  All rights reserved.
////////////////////////////////////////////////////////////////////////////

#ifndef _FM4_FLASH_H_
#define _FM4_FLASH_H_ 1

#include <tinyhal.h>

#ifndef FLASH_OP_SECTION
#define FLASH_OP_SECTION    __attribute__((section("SectionForFlashOperations")))
#endif

struct FM4_Flash_Driver
{
    typedef UINT16 CHIP_WORD;

    static BOOL FLASH_OP_SECTION ChipInitialize(void *context);
    static BOOL FLASH_OP_SECTION ChipUnInitialize(void *context);
    static const BlockDeviceInfo* FLASH_OP_SECTION  GetDeviceInfo(void *context);
    static BOOL FLASH_OP_SECTION Read(void *context, ByteAddress Address, UINT32 NumBytes, BYTE *pSectorBuff);
    static BOOL FLASH_OP_SECTION Write(void *context, ByteAddress Address, UINT32 NumBytes, BYTE *pSectorBuff, BOOL ReadModifyWrite);
    static BOOL FLASH_OP_SECTION Memset(void *context, ByteAddress Address, UINT8 Data, UINT32 NumBytes);
    static BOOL FLASH_OP_SECTION GetSectorMetadata(void* context, ByteAddress SectorStart, SectorMetadata *pSectorMetadata);
    static BOOL FLASH_OP_SECTION SetSectorMetadata(void* context, ByteAddress SectorStart, SectorMetadata *pSectorMetadata);
    static BOOL FLASH_OP_SECTION IsBlockErased(void *context, ByteAddress BlockStart, UINT32 BlockLength);
    static BOOL FLASH_OP_SECTION EraseBlock(void *context, ByteAddress Address);
    static void FLASH_OP_SECTION SetPowerState(void *context, UINT32 State);
    static UINT32 FLASH_OP_SECTION MaxSectorWrite_uSec(void *context);
    static UINT32 FLASH_OP_SECTION MaxBlockErase_uSec(void *context);
};

UINT32 FLASH_OP_SECTION sector_top(UINT32 addr);

#endif
// _FM4_FLASH_H_
